package com.mall.db.api;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.db.mapper.SmsCouponHistoryMapper;
import com.mall.pojo.SmsCouponHistory;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class SmsCouponHistoryApiImpl implements SmsCouponHistoryApi{

    @Autowired
    private SmsCouponHistoryMapper couponHistoryMapper;

    /**
     * 根据优惠券id，使用状态，订单编号分页获取领取记录
     * @param pageNum
     * @param pageSize
     * @param couponId
     * @param useStatus
     * @param orderSn
     * @return
     */
    @Override
    public Page<SmsCouponHistory> list(Integer pageNum, Integer pageSize, Integer couponId, Integer useStatus, String orderSn) {
        Page<SmsCouponHistory> page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<SmsCouponHistory> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ObjectUtil.isNotEmpty(couponId),SmsCouponHistory::getCouponId,couponId)
                .eq(ObjectUtil.isNotEmpty(useStatus),SmsCouponHistory::getUseStatus,useStatus)
                .eq(ObjectUtil.isNotEmpty(orderSn),SmsCouponHistory::getOrderSn,orderSn)
                .orderByAsc(SmsCouponHistory::getGetType);
        couponHistoryMapper.selectPage(page,wrapper);
        return page;
    }
}
